Count Shall Words in a Module

Hello,

I have a customer's requirements Microsoft Word document and I have imported it into a DOORS module. Imported module has ID column and main column with Object headings or object text. Objects with object text has one or more paragraphs. Each paragraph may have zero or one or more sentences that have a shall word, Object text paragraphs may have other sentences without shall also. 

Is there an easy and quick way to know the count of all shall words that are in the module, please?

For example, in Microsoft Word I can search for "shall" and I can get count of all shall words that are in the Customer's Word Doc.

If I use filter, it gives a count of objects that have shall words.

Is there a DOORS feature to give this count? Or do I have to write a DXL script?

If I have to write a DXL using "for each object in current module" loop, is there a function that gives count of shall words in the object text or do I have to write my own function to counts shall words in object text?

Thanks in advance to the DXL forum helping experts, please.

I need to ensure, I have same number of shall words in my imported module as the count in the customer's word doc.

Mike

 

 

 


MikeMelon - Thu Sep 25 17:06:43 EDT 2014

Re: Count Shall Words in a Module
MikeMelon - Thu Sep 25 17:16:46 EDT 2014

I have searched in this forum and found the following response. But I can not copy and paste the DXL code into text editor. Any suggestions please?

 

 

 

 

Re: Count Shall Words in a Module
MikeMelon - Thu Sep 25 17:19:39 EDT 2014

I have DOORS 9.5 version. Does this version has any feature to count shall words please?

Re: Count Shall Words in a Module
PDU - Fri Sep 26 01:43:32 EDT 2014

MikeMelon - Thu Sep 25 17:19:39 EDT 2014

I have DOORS 9.5 version. Does this version has any feature to count shall words please?

Try or adapt this script  (i can't attach file, i don't understand why)

Count all words.

// Calcul du nombre d'occurences des mots dans un module

/*
*/


pragma runLim, 0


Skip wordList = createString()
Module m = current
Object o = current
int n

Stream strmOutput  // PDU

ack "Ce script compte tous les mots des titres et texte. \nLa liste au format Tsv peut etre ouvert avec Excel."

string NomModule = m."Name"
string VersionModule = version(m) ""
string sDirectory = "c:\\Temp"
string sFileName = "ComptageMots_" NomModule "_" VersionModule ".tsv"
string sOutputFileName = sDirectory "\\" sFileName
// "c:\\Temp\\ComptageMots_" NomModule "_" VersionModule ".tsv"


// Recherche des mots dans une phrase
// On stocke les mots dans une skiplist
int findWords(string txt)
{
Regexp line = regexp "([^ \\t\\n()_':,;></\\.\"]*)"

// "
int n=0
while (!null txt && line txt)
{
    string w = lower(txt[match 0])
    if (w != "")
    {
        int n = 1
        if (find(wordList, w, n) == true)
        {
            n++
            delete(wordList, w)
        }
        put(wordList, w, n)
    }
    // match 0 is whole of match
    txt = txt[end 0 + 2:]
    ++n
}

return n
}


noError
bool fileExists_(string filename)
{
    Stat s
    s = create filename
    if (null s)
    {
        return false
    }
    delete s
    return true
}
if (fileExists_(sDirectory))
{
    // print "existe"
}
else
{
    // print "absent" ""
    mkdir (sDirectory)
    string sOpenStatus = lastError // PDU
    if (!null sOpenStatus) // PDU
    { // PDU
        ack sOpenStatus // PDU
    } // PDU    
}

noError
strmOutput = write sOutputFileName  // PDU
    string sOpenStatus = lastError // PDU
    if (!null sOpenStatus) // PDU
    { // PDU
        ack sOpenStatus // PDU
    } // PDU
    
    else
    {
    
    
    // Programme principal
    string txt
    for o in m do
    {
        txt = probeAttr_(o, "Object Text")
        n = findWords(txt)
        txt = probeAttr_(o, "Object Heading")
        n = findWords(txt)
    }    

    string sWord = ""
    int nOcc

        for nOcc in wordList do
        {
            sWord = (string key(wordList))
            strmOutput <<  sWord "\t" nOcc "\n"
        }    

    close strmOutput
    ack "liste disponible dans : " sOutputFileName ""
    system "C:\\Program Files\\Microsoft Office\\OFFICE11\\excel.exe " "\"" sOutputFileName "\"" ""
    }
    
    delete wordList

    
 

Re: Count Shall Words in a Module
lhall122 - Thu Oct 30 15:13:43 EDT 2014

I use the following dxl to count "shall" and "shall_" in a module:

 

//This DXL Program counts the number of 'shall' statements within the document.
/* created by johnsonj
 last modified 09 Sept. 02
*/

Regexp isRequirement = regexp "( shall | shall_)"

Module m = current
//Baseline b
Object o
string thisText
string mName = m."Name"
int reqCount = 0

filtering off
for o in m do {
thisText = o."Object Text"
if isRequirement thisText then {
reqCount ++
accept o
} else {
reject o
}
}
filtering on

Date   d = m."Last Modified On"

infoBox "There are " reqCount " requirements" //-
"\nin Module '" mName "'""\n"  "Last Mod: "d "\n"

Re: Count Shall Words in a Module
pommCannelle - Fri Oct 31 10:24:02 EDT 2014

lhall122 - Thu Oct 30 15:13:43 EDT 2014

I use the following dxl to count "shall" and "shall_" in a module:

 

//This DXL Program counts the number of 'shall' statements within the document.
/* created by johnsonj
 last modified 09 Sept. 02
*/

Regexp isRequirement = regexp "( shall | shall_)"

Module m = current
//Baseline b
Object o
string thisText
string mName = m."Name"
int reqCount = 0

filtering off
for o in m do {
thisText = o."Object Text"
if isRequirement thisText then {
reqCount ++
accept o
} else {
reject o
}
}
filtering on

Date   d = m."Last Modified On"

infoBox "There are " reqCount " requirements" //-
"\nin Module '" mName "'""\n"  "Last Mod: "d "\n"

You are counting objects containing shall here ... 

Here a simple snipet using the built in search function to get a proper count ... 

int countSubString ( string init, string sub ){
    if (null sub) return 0
    if (null init) return 0
    if (length(sub)>length(init)) return 0

    Buffer b = create()
    Regexp r = regexp2(sub)
    b = init
    int start = 0
    int count = 0
    while ( search(r, b, start) ){
        start = start + end(0)
        count++
    }
    delete b; delete r

    return count
}

Have fun !

Re: Count Shall Words in a Module
MikeMelon - Wed Nov 12 17:16:06 EST 2014

pommCannelle - Fri Oct 31 10:24:02 EDT 2014

You are counting objects containing shall here ... 

Here a simple snipet using the built in search function to get a proper count ... 

int countSubString ( string init, string sub ){
    if (null sub) return 0
    if (null init) return 0
    if (length(sub)>length(init)) return 0

    Buffer b = create()
    Regexp r = regexp2(sub)
    b = init
    int start = 0
    int count = 0
    while ( search(r, b, start) ){
        start = start + end(0)
        count++
    }
    delete b; delete r

    return count
}

Have fun !

Thanks a bunch to both Lisa Hall (lhall122) and Rodriguez (pommCannelle),
a combination of features of your sample scripts helped to
the code I needed to have the correct shall words count I was looking for.

I have pasted below the combination:

Again thanks a bunch for all inputs.

Mike

 

//This DXL Program counts the number of 'shall' statements within a DOORS module.
/* created by johnsonj and modified/updated by others
 last modified November 12, 2014
*/

int countSubString(string init, string sub)
{
   if (null sub) return 0
   if (null init) return 0
   if (length(sub) > length(init)) return 0
  
   Buffer b = create()
   Regexp r = regexp2(sub)
  
   b = init
   int start = 0
   int count = 0
  
   while (search(r, b, start))
   {
      start = start + end(0)
   count++
   }
   delete b; delete r;
  
   return count
}

 

Regexp isRequirement = regexp "( shall | shall_)"

Module m = current
//Baseline b
Object o
string thisText
string mName = m."Name"
int reqCount = 0
string searchStr = "shall"

int countShallWords = 0

filtering off
for o in m do
{
   thisText = o."Object Text"

   countShallWords = countSubString(thisText, searchStr)
   reqCount = reqCount + countShallWords
  
   if (countShallWords > 0)
   {
      accept o
   }
   else
   {
      reject o
   }
}
filtering on

Date   d = m."Last Modified On"

infoBox "There are " reqCount " requirements" //-
"\nin Module '" mName "'""\n"  "Last Mod: "d "\n"

 

Re: Count Shall Words in a Module
GregM_dxler - Thu Nov 13 14:13:27 EST 2014

MikeMelon - Wed Nov 12 17:16:06 EST 2014

Thanks a bunch to both Lisa Hall (lhall122) and Rodriguez (pommCannelle),
a combination of features of your sample scripts helped to
the code I needed to have the correct shall words count I was looking for.

I have pasted below the combination:

Again thanks a bunch for all inputs.

Mike

 

//This DXL Program counts the number of 'shall' statements within a DOORS module.
/* created by johnsonj and modified/updated by others
 last modified November 12, 2014
*/

int countSubString(string init, string sub)
{
   if (null sub) return 0
   if (null init) return 0
   if (length(sub) > length(init)) return 0
  
   Buffer b = create()
   Regexp r = regexp2(sub)
  
   b = init
   int start = 0
   int count = 0
  
   while (search(r, b, start))
   {
      start = start + end(0)
   count++
   }
   delete b; delete r;
  
   return count
}

 

Regexp isRequirement = regexp "( shall | shall_)"

Module m = current
//Baseline b
Object o
string thisText
string mName = m."Name"
int reqCount = 0
string searchStr = "shall"

int countShallWords = 0

filtering off
for o in m do
{
   thisText = o."Object Text"

   countShallWords = countSubString(thisText, searchStr)
   reqCount = reqCount + countShallWords
  
   if (countShallWords > 0)
   {
      accept o
   }
   else
   {
      reject o
   }
}
filtering on

Date   d = m."Last Modified On"

infoBox "There are " reqCount " requirements" //-
"\nin Module '" mName "'""\n"  "Last Mod: "d "\n"

 

Hi,

The search string should include a space before/after the word "shall" so that you don't accidently count marshall as a shall!

The regular expression isRequirement contains the space, but I don't see where you are using that in this snippet.

Say thanks to Louie to point this out.

 

Hope this helps,

Greg